package com.leyou.auth.config;

import com.leyou.common.auth.utils.RsaUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.context.properties.ConfigurationProperties;

import javax.annotation.PostConstruct;
import java.security.PrivateKey;
import java.security.PublicKey;

//加载数据
@Data
@Slf4j
@ConfigurationProperties(prefix = "ly.jwt")
public class JwtProperties {

    private String pubKeyPath;
    private String priKeyPath;

    private LoadUserInfo user=new LoadUserInfo();

    //在当前对象创建完成并且私有属性被DI（给属性赋值）后创建出两个key
    private PrivateKey privateKey;
    private PublicKey publicKey;

    //过期时间
    @Data
    public class LoadUserInfo{
        private int expire;
        private String cookieName;
        private String cookieDomain;
    }


    @PostConstruct //创建之后执行此方法
    public void createKey() throws Exception {
        privateKey=RsaUtils.getPrivateKey(priKeyPath);
        publicKey=RsaUtils.getPublicKey(pubKeyPath);
    }


}